package org.consistenthash;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ConcurrentHashMapTest {

    public static ConcurrentHashMap<String,Integer> map = new ConcurrentHashMap<>();
    public static HashMap<String,Integer> map2 = new HashMap<>();
    Map m2 = Collections.synchronizedMap(map2);


    public static void main(String[] args) {

        Integer count = map.get("count");
        if(count ==null) {
            map.put("count",1);
        }else{
            map.put("count",count+1);
        }


        while(true)  {
            Integer count2 = map.get("count");

            if(count == null) {
                if(map.putIfAbsent("count",1) == null) {
                    break;
                }else {
                    if(map.replace("count", count2,count+1)){
                        break;
                    }

                }
            }
        }
    }
}
